#include <iostream>

class Fruit {
    public:
        // using ptr = std::share_ptr<Fruit>;
        Fruit(){}
        virtual void show() = 0;
};
class Apple : public Fruit {
    public:
        Apple() {}
        virtual void show() {
            std::cout << "我是一个苹果" << std::endl;
        }
};
class Banana : public Fruit {
    public:
        Banana() {}
        virtual void show() {
            std::cout << "我是一个香蕉" << std::endl;
        }
};


class FruitFactory {
public:
    static std::shared_ptr<Fruit> create(const std::string &name)
    {
        if(name == "苹果")
        {
            std::shared_ptr<Fruit> ret = std::make_shared<Apple>();
            return ret;
        }
        else
        {
            std::shared_ptr<Fruit> ret = std::make_shared<Banana>();
            return ret;
        }
    }

    
}



std::mutex _mutex;

class Singleton { 
private:
    Singleton(){}
    ~Singleton(){}
public: 
    Singleton(const Singleton&) = delete;
    Singleton& operator=(const Singleton&) = delete;
    static Singleton* getInstance() 
    { 
        if(etno == nullptr)
        {
            _mutex.lock();
            if(etno == nullptr)
            {
                etno = new Singleton();
            }
            _mutex.unlock();
        }
        return etno;
    } 
private:
    static Singleton* etno;
};

Singleton* Singleton::etno = nullptr;





void printNum(int n, ...) {
    va_list al;
    va_start(al, n);
    for (int i = 0; i < n; i++) {
        int num = va_arg(al, int);//从可变参数中取出一个整形参数
        std::cout << num << std::endl;
    }
    va_end(al);//清空可变参数列表--其实是将al置空
}
